package com.wlcorp.forcazamis.business.baseinfo.impl;

import java.util.List;

import com.wlcorp.forcazamis.business.baseinfo.ICustomerService;
import com.wlcorp.forcazamis.dao.baseinfo.ICustomerDAO;
import com.wlcorp.forcazamis.domain.baseinfo.Customer;
import com.wlcorp.forcazamis.exception.ServiceException;
import com.wlcorp.forcazamis.sys.BaseService;
import com.wlcorp.forcazamis.sys.util.AppConstant;

public class CustomerServiceImpl extends BaseService implements ICustomerService {
	
	private ICustomerDAO customerDAO;
	public List<Customer> getCustomerList(Customer customer, Long staffId) throws ServiceException {
		return customerDAO.getCustomerList(customer, staffId);
	}

	public Customer getCustomerById(Long customerId) throws ServiceException {
		if(null == customerId){
			return null;
		}
		return customerDAO.getCustomerById(customerId);
	}

	public void saveCustomer(Customer customer) throws ServiceException {
		if(null == customer.getCustomerId()){
			Customer tmpCustomer = new Customer();
			tmpCustomer.setCustomerName(customer.getCustomerName());
			Long count = customerDAO.getCustomerCount(customer);
			if(count > 0){
				setErrorField(customer,AppConstant.BASE_BEAN_STATUS_ERROR,"客户简称重复，请重新输入！");
				return;
			}
		}
		customerDAO.saveCustomer(customer);
	}

	public void setCustomerDAO(ICustomerDAO customerDAO) {
		this.customerDAO = customerDAO;
	}

	public Long getCustomerCount(Customer customer) throws ServiceException {
		return customerDAO.getCustomerCount(customer);
	}

	public void deleteCustomer(Customer customer) throws ServiceException {
		//删除条件待定
		customerDAO.deleteCustomer(customer);
	}
	
}
